const Router = require('koa-router')
const controller = require('../controller')
const authRequired = require('../middleware/auth-required')

const router = new Router()

router.get('/', async ctx => {
  ctx.body = 'Hi, api'
})

router.get('/test', async ctx => {
  ctx.session.views = ctx.session.views ? ctx.session.views + 1 : 1

  ctx.body = ctx.session
})

router.post('/login', controller.user.login)
router.post('/register', controller.user.register)
router.get('/login/info', controller.user.getLoginInfo)
router.post('/send/code', controller.user.sendCode)

router.post('/task/create', authRequired, controller.task.createTask)
router.post('/task/update', authRequired, controller.task.updateTask)
router.get('/task/delete', authRequired, controller.task.deleteTask)
router.get('/task/list', authRequired, controller.task.getTaskList)

router.post('/collection/create', authRequired, controller.task.createCollection)
router.post('/collection/update', authRequired, controller.task.updateCollection)
router.get('/collection/delete', authRequired, controller.task.deleteCollection)
router.get('/collection/list', authRequired, controller.task.getCollectionList)

router.post('/doc/create', authRequired, controller.doc.createDoc)
router.post('/doc/update', authRequired, controller.doc.updateDoc)
router.get('/doc/delete', authRequired, controller.doc.deleteDoc)
router.get('/doc/list', controller.doc.docList)
router.get('/doc/tocs', controller.doc.getDocTocList)
router.get('/doc/info', controller.doc.getDocInfo)

router.post('/toc/create', authRequired, controller.doc.addToc)
router.post('/toc/update', authRequired, controller.doc.updateToc)
router.get('/toc/delete', authRequired, controller.doc.deleteToc)

router.post('/post/create', authRequired, controller.post.createPost)
router.post('/post/update', authRequired, controller.post.updatePost)
router.get('/post/delete', controller.post.deletePost)
router.get('/post/info', controller.post.getPostInfo)

module.exports = router
